package com.wallet.trans.controller;


import com.safeheron.client.webhook.WebHook;
import com.safeheron.client.webhook.WebHookResponse;
import com.wallet.trans.services.MpcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/v1/mpc/callback")
public class MpcCallBackController {

    @Autowired
    MpcService mpcService;

    /**
     * @param info
     * API co-signer节点服务器自动审核回调接口
     * */
    @PostMapping("/webHook")
    public WebHookResponse mpcCoSigner(@RequestBody WebHook info) {
        WebHookResponse webHookResponse = new WebHookResponse();
//        logger.info("[mpcCoSigner]--info:{}", info);
        try {
            webHookResponse = mpcService.webHookCallBack(info.getTimestamp(), info.getSig(), info.getKey(), info.getBizContent());
        }catch (Exception e){
            throw new RuntimeException(e);
        }catch (Throwable e){
            throw new RuntimeException(e);
        }
        return webHookResponse;
    }
}
